package com.quzi.kettle.activitise.process;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.quzi.kettle.R;
import com.quzi.kettle.activitise.BaseActivity;
import com.quzi.kettle.view.TitleBarView;

public class DeviceList extends BaseActivity{

	private ListView deviceList;
	private TitleBarView title;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_devicelist);
		
		initTitleBar();
		
		deviceList = (ListView) findViewById(R.id.devicelist);
		String[] title = {"我的水壶1", "我的水壶2"};
		int[] imgs = {R.drawable.ic_launcher, R.drawable.ic_launcher};
		deviceList.setAdapter(new dataListAdapter(title, imgs));
	}
	
	@Override
	protected void initTitleBar() {
		// TODO Auto-generated method stub
		super.initTitleBar();
		title = (TitleBarView) findViewById(R.id.titleview);
		title.setTitle(getResources().getString(R.string.mykettle));
	}
	
	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		
	}

	
	class dataListAdapter extends BaseAdapter {
        String[] Title, Detail;
        int[] imge;

        dataListAdapter() {
            Title = null;
            Detail = null;
            imge=null;
        }

        public dataListAdapter(String[] text,int[] text3) {
            Title = text;
            imge = text3;

        }

        public int getCount() {
            // TODO Auto-generated method stub
            return Title.length;
        }

        public Object getItem(int arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
        		ViewHolder viewHolder;
        		if(convertView == null){
        			viewHolder = new ViewHolder();
        			LayoutInflater inflater = getLayoutInflater();
        			convertView = inflater.inflate(R.layout.device_item, null);
        			viewHolder.img = (ImageView) convertView.findViewById(R.id.device_img);
        			viewHolder.title = (TextView) convertView.findViewById(R.id.name);
//        			viewHolder.info = (TextView) convertView.findViewById(R.id.des);
        			convertView.setTag(viewHolder);
        		}else{
        			viewHolder = (ViewHolder) convertView.getTag();
        		}
        		for(int i=0;i<imge.length;i++){
        			viewHolder.img.setImageResource(imge[i]);
        			viewHolder.title.setText(Title[i]);
        		}
        		return convertView;
        }
    }

	static class ViewHolder
	{
	    public ImageView img;
	    public TextView title;
	    public TextView info;
	}
	
}
